/**
 * Created by Administrator on 2017-01-06.
 */


var http = require('http');

http.createServer(function(request, response) {

    request.on('error', function(err) {
        console.error(err);
        response.statusCode = 400;
        response.end();
    });
    response.on('error', function(err) {
        console.error(err);
    });
    if (request.method === 'GET' && request.url === '/echo') {
       // request.pipe(response);

        //response.end(JSON.stringify(request.headers))

        response.writeHead(302, {
            'Location': 'http://www.baidu.com'});
        response.end()
    } else {
        response.statusCode = 404;
        response.end();
    }
}).listen(8080);